package com.ysmygx.utils;

import lombok.Data;

@Data
public class R<T> {
    /**
     * 成功标记：成功为0，失败为1
     */
    private Integer code;
    private String msg;
    private T data;

    public R(Integer code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public R(){
        this(0, "success", null);
    }


    public static R ok(){
        return new R();
    }

    public static <T> R ok(T data){
        return new R<T>(0, "success", data);
    }

    public static <T> R ok(T data, String msg){
        return new R<T>(0, msg, data);
    }

    public static R failed(){
        return new R(1, "failed", null);
    }

    public static R failed(String msg){
        return new R(1, msg, null);
    }

    public static <T> R failed(T data){
        return new R<T>(1, "failed", data);
    }

    public static <T> R failed(T data, String msg){
        return new R<T>(1, msg, data);
    }
}
